package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.dto.AddUserDto;
import com.sangeng.domain.dto.UpdateUserDto;
import com.sangeng.domain.vo.UserVo;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @GetMapping("/list")
    public ResponseResult<PageVo> getUserListByTitle(Integer pageNum, Integer pageSize, String userName, String status) {
        return userService.getUserByUserName(pageNum, pageSize, userName, status);
    }

    @PostMapping
    public ResponseResult<String> addUser(@RequestBody @Validated AddUserDto userDto) {
        return userService.addUser(userDto);
    }

    //修改分类 先获取数据 然后修改的时候自动填充到那个框上
    @GetMapping("/{id}")
    public ResponseResult<UserVo>  getUser(@PathVariable Long id) {
        return userService.getUserById(id);
    }
    @PutMapping
    public ResponseResult<String> updateUser(@RequestBody UpdateUserDto userDto) {
        return userService.updateUser(userDto);
    }

    //多选删除
    @DeleteMapping("/{idList}")
    public ResponseResult<String> deleteUser(@PathVariable List<Long> idList) {
        return userService.deleteUserById(idList);
    }
}